package com.example.test_event_and_callback.infras.async;

import java.lang.reflect.Method;
import java.util.Map;

public class ProviderProcessorReflection extends AsyncProviderProcessor<Method>{

    public ProviderProcessorReflection(Class<?> demanderClass) {
        super(demanderClass);
    }

    @Override
    void loadProviderMethodMap(Map<String, Method> mappedMethodByParam) {
        providerMethodMap = mappedMethodByParam;
    }

    @Override
    void putMethodToMap(Map<String, Method> map, String paramName, Method method) {
        map.put(paramName, method);
    }

    @Override
    Demander proxyDataDemander(Object demander) {
        return new AsyncDemanderProxy(demander);
    }

    @Override
    Object executeProviderMethod(Object method, Object provider, String s) {
        try {
            return ((Method)method).invoke(provider,s);
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

}
